/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tardisdatadepositor;

/**
 *
 * @author steve
 */
import javax.swing.JDialog;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JTextField;

// TODO: add 'enter' event and maybe field for size of text field?

public class InputDialog extends JDialog implements ActionListener {
    private JPanel myPanel = null;
    private JButton okButton = null;
    private JTextField answerField = null;

    public String getAnswer() { return answerField.getText(); }

    public InputDialog(JFrame frame, boolean modal, String myMessage) {
        super(frame, modal);
        myPanel = new JPanel();
        getContentPane().add(myPanel);
        myPanel.add(new JLabel(myMessage));

        answerField = new JTextField(16);
        answerField.addKeyListener(new KeyAdapter() {
      public void keyPressed(KeyEvent evt) {
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER)
          setVisible(false);
      }
    });
        myPanel.add(answerField);

        okButton = new JButton("OK");
        okButton.addActionListener(this);
        myPanel.add(okButton);

        pack();
        setLocationRelativeTo(frame);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if(okButton == e.getSource()) {
            //System.err.println("User chose " + getAnswer());

            setVisible(false);
        }
    }

}